package main

type ListNode struct{
	Val int
	Next *ListNode
}

func mergeTwoLists(l1 *ListNode, l2 *ListNode) *ListNode{
	// 定义一个哑结点
	dummy := &ListNode{0,nil}
	// ptail指向已经处理好的链表末尾
	ptail := dummy
	p1,p2 := l1,l2
	for{
		if p1==nil{
			ptail.Next = p2
			break
		}
		if p2==nil{
			ptail.Next = p1
			break
		}
		if p1.Val>p2.Val{
			ptail.Next = p2
			p2 = p2.Next
			ptail = ptail.Next
		}else{
			ptail.Next = p1
			p1 = p1.Next
			ptail = ptail.Next
		}
	}
	return dummy.Next
}
